<!DOCTYPE html>
<html lang="en">


{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">商品列表</div>
                        </div>
                        <div class="widget-body  am-fr">
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-1" >
                                <div class="am-form-group" >
                                    <div class="am-btn-toolbar" >
                                        <div class="am-btn-group am-btn-group-xs" >
                                            <a href="{:Url('add2')}" class="am-btn am-btn-default am-btn-success" ><span class="am-icon-plus" ></span> 新增</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--筛选搜索-->
                            <form action=""></form>
                            <form id="searchform" action="{:Url('index')}"  method="get" class="am-form tpl-form-border-form tpl-form-border-br">
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-1">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select  name="cat_id" >
                                            <option value="-1">选择分类</option>
                                            {foreach name="categoryList" key="k" item="v"}
                                              <option value="{$k}">{$v}<option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-1">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select  name="brand_id" >
                                            <option value="-1">选择品牌</option>
                                            {foreach name="brand" key="k" item="v"}
                                              <option value="{$k}">{$v}<option>
                                            {/foreach}
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-1">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select  name="is_on_sale" >
                                            <option value="-1">选择是否上架</option>
                                            <option value="0">否</option>
                                            <option value="1">上架</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-1">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select  name="is_new" >
                                            <option value="-1">选择是否新品</option>
                                            <option value="0">否</option>
                                            <option value="1">新品</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-1">
                                    <div class="am-form-group tpl-table-list-select">
                                        <select  name="is_recommend" >
                                            <option value="-1">选择是否推荐</option>
                                            <option value="0">否</option>
                                            <option value="1">推荐</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-1">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <input type="text" class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"  name="goods_name" placeholder="商品名">
                                    </div>
                                </div>

                                <div class="am-u-sm-12 am-u-md-6 am-u-lg-2" style="float: left;">
                                    <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                        <span class="am-input-group-btn">
                                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" type="submit" ></button>
                                        </span>
                                    </div>
                                </div>

                            </form>
                            <div class="am-u-sm-12">
                                <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                    <thead>
                                    <tr>

                                        <th>商品id</th>
                                        <th>商品名称</th>
                                        <th>商品编号</th>
                                        <th>分类</th>
                                        <th>价格</th>
                                        <th>库存</th>
                                        <th>上架</th>
                                        <th>推荐</th>
                                        <th>新品</th>
                                        <th>热卖</th>
                                        <!--<th>排序</th>-->
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {foreach name="data" key="key" item="value"}
                                    <tr class="gradeX">
                                        <td>{$value.goods_id}</td>
                                        <td>{$value.goods_name|mb_substr=0,33}</td>
                                        <td>{$value.goods_sn}</td>
                                        <td>{$value.cat_id}</td><!--分类-->
                                        <td>{$value.market_price}</td><!--价格-->
                                        <td>{$value.store_count}</td><!--库存-->
                                        <!--上架-->
                                        <td>
                                        {if $value.is_on_sale eq 1}
                                        <button type="button" class="btn btn-primary btn-sm" onclick="changedisable(this)" data-val="0" data-type="is_on_sale"  masterid='{$value.goods_id}'><i class="fa fa-check" ></i>是</button>
                                        {else}
                                        <button class="btn btn-default btn-sm " type="button" onclick="changedisable(this)" data-val="1" data-type="is_on_sale" masterid='{$value.goods_id}' ><i class="fa fa-times" ></i>
                                            <span class="bold" >否</span>
                                        </button>
                                        {/if}
                                        </td>
                                        <!--推荐-->
                                        <td>
                                        {if $value.is_recommend eq 1}
                                        <button type="button" class="btn btn-primary btn-sm" onclick="changedisable(this)" data-val="0" data-type="is_recommend" masterid='{$value.goods_id}'><i class="fa fa-check" ></i>&nbsp;是</button>
                                        {else}
                                        <button class="btn btn-default btn-sm " type="button" onclick="changedisable(this)" data-val="1" data-type="is_recommend" masterid='{$value.goods_id}' ><i class="fa fa-times" ></i>
                                            <span class="bold" >否</span>
                                        </button>
                                        {/if}
                                        </td>
                                        <!--新品-->
                                        <td>
                                        {if $value.is_new eq 1}
                                        <button type="button" class="btn btn-primary btn-sm" onclick="changedisable(this)" data-val="0" data-type="is_new" masterid='{$value.goods_id}'><i class="fa fa-check" ></i>&nbsp;是</button>
                                        {else}
                                        <button class="btn btn-default btn-sm " type="button" onclick="changedisable(this)" data-val="1" data-type="is_new" masterid='{$value.goods_id}' ><i class="fa fa-times" ></i>
                                            <span class="bold" >否</span>
                                        </button>
                                        {/if}
                                        </td>
                                        <!--热卖-->
                                        <td>
                                        {if $value.is_hot eq 1}
                                        <button type="button" class="btn btn-primary btn-sm" onclick="changedisable(this)" data-val="0" data-type="is_hot" masterid='{$value.goods_id}'><i class="fa fa-check" ></i>&nbsp;是</button>
                                        {else}
                                        <button class="btn btn-default btn-sm " type="button" onclick="changedisable(this)" data-val="1" data-type="is_hot" masterid='{$value.goods_id}' ><i class="fa fa-times" ></i>
                                            <span class="bold" >否</span>
                                        </button>
                                        {/if}
                                        </td>
                                        <!--<td>{$value.sort}</td>&lt;!&ndash;排序&ndash;&gt;-->
                                        <td>
                                            <div class="tpl-table-black-operation">
                                                <a href="{:Url('add2')}?goods_id={$value.goods_id}" class="btn btn-primary" title="编辑"><i class="fa fa-pencil"></i></a>
                                                <a href="javascript:void(0);" onclick="del_button('{$value.goods_id}')" class="btn btn-danger" title="删除"><i class="fa fa-trash-o"></i></a>
                                            </div>
                                        </td>
                                    </tr>
                                    {/foreach}
                                    <!-- more data -->
                                    </tbody>
                                </table>
                            </div>
                            <div class="am-u-lg-10 am-cf">

                                <div class="am-fr">
                                    <ul class="am-pagination tpl-pagination">
                                        {$data->render()}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
{include file='Public:script'}
<link href="/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css">
<script src="/daterangepicker/moment.min.js" type="text/javascript"></script>
<script src="/daterangepicker/daterangepicker.js" type="text/javascript"></script>

<script>
    // 删除按钮
    function shan(id){
        $.post("{:url('Goods/Delete')}",{id:id},function (res) {
            if(res.code ==200){
                alert(res.msg);
                location.reload();
            }else{
                alert(res.msg);
            }
        });

    }

    //提交
    function roleSubmit() {
        var form = document.getElementById("searchform");
        var formData = new FormData(form);
        $.ajax({
            url: "{:Url('index')}",
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success: function (res) {
                console.log(res);
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 2});
                    return false;
                }
                layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function () {
                    window.location.href = document.referrer;

                });
            }
        })
    }

    //选择时间js
    $(document).ready(function() {
        $('#start_time').daterangepicker({
            format:"YYYY-MM-DD",
            singleDatePicker: false,
            showDropdowns: true,
            minDate:'2016-01-01',
            maxDate:'2030-01-01',
            startDate:'2016-01-01',
            showWeekNumbers: true,
            timePicker: false,
            timePickerIncrement: 1,
            timePicker12Hour: true,
            ranges: {
                '今天': [moment(), moment()],
                '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
                '最近7天': [moment().subtract('days', 6), moment()],
                '最近30天': [moment().subtract('days', 29), moment()],
                '上一个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
            },
            opens: 'right',
            buttonClasses: ['btn btn-default'],
            applyClass: 'btn-small btn-primary',
            cancelClass: 'btn-small',
            locale : {
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        });
    });

    // 启用禁用修改
    function changedisable(e,d){
        type = $(e).attr('data-type');
        goods_id      = $(e).attr('masterid');
        is = $(e).attr('data-val');

        // 状态修改
        $.post("{:url('change')}", {goods_id: goods_id, is: is,type:type}, function(ret){
            if(ret.code != 200){
                layer.tips(ret.msg, e, {tips: [4, 'red']});
            }

            layer.msg(ret.msg, {time: 500, shift: 4}, function(){
                if(is == 0) {
                    $(e).toggleClass('btn-default');
                    $(e).toggleClass('btn-primary');
                    $(e).html("<i class='fa fa-times'></i> <span class='bold'>下架</span>");
                    $(e).attr('data-val','1');
                    return false;
                }

                $(e).toggleClass('btn-default');
                $(e).toggleClass('btn-primary');
                $(e).html("<i class='fa fa-check'></i>&nbsp;上架");
                $(e).attr('data-val','0');
                return false;
            });
        });
    }
</script>
</html>